package cn.ecut.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;

/**
 * @author lujiapeng
 * @className FileUploadServlet
 * @description 是针对于 文件上传 , 在文件上传中，经常在 web.xml 中进行配置
 * @date 2020/9/11 10:20
 **/

public class FileUploadServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        throw new RuntimeException("不支持Get方式上传文件") ;
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Part source = request.getPart("source");
        System.out.println( source );

        System.out.println( source.getName() );
        System.out.println( source.getSize() );
        System.out.println( source.getSubmittedFileName() );
        System.out.println( source.getContentType() );

        source.write( source.getSubmittedFileName() );
    }
}
